// 导入组件
import Vue from 'vue';
import VueRouter from 'vue-router';
//导入页面
import {startpage, home,menus,shoppingcart,my,addressdetail, addresslist} from '@/views'

// 启用路由
Vue.use(VueRouter);
// 解决通过路由进行当前页面点击报错问题
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
};
// 导出路由 
const router = new VueRouter({
  routes: [{
    path: '/',
    name: 'startpage',
    component: startpage,
    hidden: true,
    meta: {
      name: '启动页'
    }
  }, {
    path: '/home',
    name: 'home',
    component: home,
    hidden: true,
    meta: {
      name: '首页'
    }
  }, {
    path: '/menus',
    name: 'menus',
    component: menus,
    hidden: true,
    meta: {
      name: '菜单'
    }
  }, {
    path: '/shoppingcart',
    name: 'shoppingcart',
    component: shoppingcart,
    hidden: true,
    meta: {
      name: '购物车'
    }
  }, {
    path: '/my',
    name: 'my',
    component: my,
    hidden: true,
    meta: {
      name: '我的'
    }
  },{
    path: '/addressdetail',
    name: 'addressdetail',
    component: addressdetail,
    hidden: true,
    meta: {
      name: '地址详情'
    }
  },{
    path: '/addresslist',
    name: 'addresslist',
    component: addresslist,
    hidden: true,
    meta: {
      name: '地址列表'
    }
  }, 
  ]
})
export default router

// router.beforeEach((to, from, next) => {
//     if (to.meta.requireAuth) {       //页面用不用判断是否登录
//         if (JSON.parse(sessionStorage.getItem('json'))) { // 如果已经有登录状态的话，走下一个页面
//             next();
//         } else {
//             if (to.path === '/login') { // 如果是登录页面的话，直接next()
//                 next();
//             } else { // 否则 跳转到登录页面
//                 next({
//                     path: '/login'
//                 });
//             }
//         }
//     } else {
//         next();
//     }

// })